36 #include "sensor_drv.h" 37 #include "sensor_io_i2c.h" 40 #define MAG3110_COUNTSPERUT 10 // fixed range for MAG3110 magnetometer 47 { .readFrom = MAG3110_WHO_AM_I, .numBytes = 1 }, __END_READ_DATA__
53 { .readFrom = MAG3110_DR_STATUS, .numBytes = 1 }, __END_READ_DATA__
59 { .readFrom = MAG3110_OUT_X_MSB, .numBytes = 6 }, __END_READ_DATA__
68 { MAG3110_CTRL_REG1, 0x00, 0x00 },
76 { MAG3110_CTRL_REG2, 0x90, 0x00 },
87 #if (MAG_ODR_HZ <= 10) // select 10Hz ODR 88 { MAG3110_CTRL_REG1, 0x19, 0x00 },
89 #elif (MAG_ODR_HZ <= 30) // select 20Hz ODR (to give lower noise with standard 25Hz build) 90 { MAG3110_CTRL_REG1, 0x11, 0x00 },
91 #elif (MAG_ODR_HZ <= 40) // select 40Hz ODR 92 { MAG3110_CTRL_REG1, 0x09, 0x00 },
93 #else // select 80Hz ODR 94 { MAG3110_CTRL_REG1, 0x01, 0x00 },
102 #pragma optimize=no_scheduling 107 status = Register_I2C_Read(sensor->
bus_driver, sensor->
addr, MAG3110_WHO_AM_I, 1, ®);
108 if (status==SENSOR_ERROR_NONE) {
110 if (reg!=MAG3110_WHOAMI_VALUE) {
111 return(SENSOR_ERROR_INIT);
116 return(SENSOR_ERROR_INIT);
136 uint8_t I2C_Buffer[6];
142 return SENSOR_ERROR_INIT;
146 sample[
CHX] = (I2C_Buffer[0] << 8) | I2C_Buffer[1];
147 sample[
CHY] = (I2C_Buffer[2] << 8) | I2C_Buffer[3];
148 sample[
CHZ] = (I2C_Buffer[4] << 8) | I2C_Buffer[5];
149 if (status==SENSOR_ERROR_NONE) {
151 sample[
CHZ] = -sample[
CHZ];
163 { MAG3110_CTRL_REG1, 0x00, 0x00 },
176 return SENSOR_ERROR_INIT;
const registerreadlist_t MAG3110_DR_STATUS_READ[]
const registerreadlist_t MAG3110_WHO_AM_I_READ[]
#define CHY
Used to access Y-channel entries in various data data structures.
void addToFifo(FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
The top level fusion structure.
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
#define MAG_FIFO_SIZE
FXOS8700 (mag), MAG3110 have no FIFO so equivalent to 1 element FIFO.
int16_t iCountsPeruT
counts per uT
MagSensor Mag
magnetometer storage
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
const registerwritelist_t MAG3110_IDLE[]
float fuTPerCount
uT per count
bool isEnabled
true if the device is sampling
The sensor_fusion.h file implements the top level programming interface.
int8_t MAG3110_Read(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
Provides function prototypes for driver level interfaces.
#define CHX
Used to access X-channel entries in various data data structures.
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two's complement value for a 16-...
float fCountsPeruT
counts per uT
An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo dev...
const registerwritelist_t MAG3110_Initialization[]
int8_t MAG3110_Init(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
registerreadlist_t MAG3110_DATA_READ[]
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
#define MAG3110_COUNTSPERUT
uint8_t iWhoAmI
sensor whoami
int8_t MAG3110_Idle(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
SensorFusionGlobals sfg
This is the primary sensor fusion data structure.
uint16_t addr
I2C address if applicable.